package com.zhuoyue.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletRequest;


import com.zhuoyue.common.annotation.Log;
import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.domain.entity.SysDept;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.enums.BusinessType;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.system.domain.dto.RoomPoReqDTO;
import com.zhuoyue.system.domain.po.TblRoomPo;
import com.zhuoyue.system.domain.vo.TblRoomVo;
import com.zhuoyue.system.mapper.SysDeptMapper;
import com.zhuoyue.web.utils.OrgCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhuoyue.system.service.ITblRoomService;


/**
 * 房间Controller
 *
 * @author hewenze
 * @date 2020-08-06
 */
@RestController
@Api(value = "房间接口", tags = "房间接口")
@RequestMapping("/system/room")
public class TblRoomController extends BaseController {
    @Autowired
    private ITblRoomService tblRoomService;

    @Autowired
    private OrgCodeUtils orgCodeUtils;

    @Autowired
    private SysDeptMapper sysDeptMapper;

    /**
     * 查询房间列表
     */
    @ApiOperation(value = "查询房间列表", notes = "查询房间列表")
    @GetMapping("/list")
    public TableDataInfo list(RoomPoReqDTO roomPoReq, HttpServletRequest request) {

        if (roomPoReq.getDeptId() == null) {
            roomPoReq.setOrganizationCode(orgCodeUtils.getOrgCode(request));
        } else {
            SysDept sysDept = sysDeptMapper.selectDeptById(roomPoReq.getDeptId());
            roomPoReq.setOrganizationCode(sysDept.getOrgCode());
        }
        TblRoomPo tblAppRoomPo = new TblRoomPo().dtoToDo(roomPoReq);
        startPage();
        List<TblRoomVo> list = tblRoomService.selectTblRoomList(tblAppRoomPo);
        return getDataTable(list);
    }

    /**
     * 导出房间列表
     */
    @ApiOperation(value = "导出房间列表", notes = "导出房间列表")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TblRoomPo tblAppRoomPo, HttpServletRequest request) {
        tblAppRoomPo.setOrganizationCode(orgCodeUtils.getOrgCode(request));
        tblAppRoomPo.setPageNum(null);
        tblAppRoomPo.setPageSize(null);
        List<TblRoomVo> list = tblRoomService.selectTblRoomList(tblAppRoomPo);
        ExcelUtil<TblRoomVo> util = new ExcelUtil<TblRoomVo>(TblRoomVo.class);
        return util.exportExcel(list, "房间");
    }

}
